package org.loong.crypto.service.software.context;

import java.security.Provider;
import java.security.SecureRandom;

import org.loong.crypto.core.GlobalBouncyCastleProvider;
import org.loong.crypto.service.core.context.CryptoContext;

public class SoftwareCryptoContext extends CryptoContext {

    /**
     * The provider.
     */
    private Provider provider;

    /**
     * builder constructor.
     * 
     * @param builder the builder
     */
    public SoftwareCryptoContext(final Builder builder) {
        this.provider = builder.provider;
        setRandom(builder.random);
    }

    /**
     * class builder.
     *
     * @return Builder
     */
    public static Builder builder() {
        return new Builder();
    }

    /**
     * Gets the value of provider.
     *
     * @return the value of provider
     */
    public Provider getProvider() {
        return provider;
    }

    /**
     * Sets the provider.
     *
     * @param provider the provider to set
     */
    public void setProvider(final Provider provider) {
        this.provider = provider;
    }

    /**
     * class builder.
     */
    public static final class Builder {

        private Provider provider = GlobalBouncyCastleProvider.INSTANCE.getProvider();

        private SecureRandom random;

        /**
         * no args constructor.
         */
        private Builder() {}

        /**
         * build new Object.
         *
         * @return the {@link SoftwareCryptoContext}
         */
        public SoftwareCryptoContext build() {
            return new SoftwareCryptoContext(this);
        }

        /**
         * build provider.
         *
         * @param provider the provider
         * @return this
         */
        public Builder provider(final Provider provider) {
            this.provider = provider;
            return this;
        }

        /**
         * build random.
         *
         * @param random the random
         * @return this
         */
        public Builder random(final SecureRandom random) {
            this.random = random;
            return this;
        }
    }
}
